// common/components/daterange/daterange.js
const dayjs = require('dayjs')
Component({
  externalClasses: ['hyy-class'],
  /**
   * 组件的属性列表
   */
  properties: {
    startTime: {
      type: String,
      value: ''
    },
    endTime: {
      type: String,
      value: ''
    },
  },
  observers: {
    'startTime,endTime': function (s, e) {
      this.setData({
        _startTime: s || '',
        _endTime: e || ''
      })
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    visible: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onStart() {
      this.setData({
        visible: true
      });
    },
    onEnd() {
      this.setData({
        visible: true
      });
    },
    handleConfirm(e) {
      const st = dayjs(e.detail.value[0]).format('YYYY-MM-DD')
      const et = dayjs(e.detail.value[1]).format('YYYY-MM-DD')
      this.setData({
        _startTime: st,
        _endTime: et,
      })
      this.triggerEvent('change', {
        value: [st, et]
      })
    }
  }
})